package com.chat.biz.controller;

import com.chat.api.dto.AuthCodeDTO;
import com.chat.api.dto.AuthSetDTO;
import com.chat.api.dto.LoginDTO;
import com.chat.api.entity.User;
import com.chat.biz.service.AuthService;

import com.chat.common.result.R;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 身份验证控制器
 *
 * @author chenhao
 * @date 2025/06/09
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 登记
     *
     * @param loginDTO 登录到
     * @return {@link R }<{@link Void }>
     */
    @PostMapping("/register")
    public R<Void> register(@RequestBody @Validated LoginDTO loginDTO) {
        authService.register(loginDTO);
        return R.ok();
    }

    /**
     * 注册
     *
     * @param loginDTO 登录到
     * @return {@link R }<{@link String }>
     */
    @PostMapping("/login")

    public R<String> login(@RequestBody @Validated LoginDTO loginDTO) {
        String token = authService.login(loginDTO);
        return R.ok(token);
    }

    /**
     * 发送验证码
     *
     * @param phone 电话
     * @return {@link R }<{@link Void }>
     */
    @PostMapping("sendcode")
    public R<Void> sendCode(@RequestParam("phone") String phone) {
        authService.sendCode(phone);
        return R.ok();
    }

    /**
     * 查找密码
     *
     * @param dto 到
     * @return {@link R }<{@link Void }>
     */
    @PostMapping("findpassword")
    public R<Void> findpassword(@RequestBody @Validated AuthCodeDTO dto) {
        authService.findpassword(dto);
        return R.ok();
    }
}
